﻿using BasicData.Infrastructure.interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BasicData.Infrastructure.Implement
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly BasicDataDbContext db;

        public BaseRepository(BasicDataDbContext db)
        {
            this.db = db;
        }

        public async Task<int> AddAllAsync(List<T> item)
        {
            await db.Set<T>().AddRangeAsync(item);
            return await db.SaveChangesAsync();
        }

        public async Task<int> AddAsync(T item)
        {
            await db.Set<T>().AddAsync(item);
            return await db.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>();
        }
    }
}
